<?php

    require ( 'init.inc.php' );
    require ( 'checkadmin.inc.php');
    require ( __COMM_PATH . 'pagecontrol.inc.php' );
    require ( __COMM_PATH . 'checkform.func.php' );
    require ( __CLASS_PATH . 'page_edit.class.php' );

    // -------------------------------------------------------
    // 接收传递过来的变量
    // -------------------------------------------------------
    $action = $_REQUEST["action"];
    $id     = addslashes($_REQUEST["id"]);
    //$classid= intval($_GET["classid"]);
    //if (!is_numeric($classid)) feedback($clang["pls_enter_news_class"]);

    // -------------------------------------------------------
    // 页面基本设置
    // -------------------------------------------------------
    $page_title   = $ptitle["ad_edit"];
    $page_type    = "edit";
    $display_page = "ad_edit.htm";
    $table_name   = "{$tablepre}advertisement";
    $condition    = "WHERE `id`='{$id}'";
    $back_page    = "ad_list.php?sortby={$_GET['sortby']}&oexp={$_GET['oexp']}&page={$_GET['page']}&classid={$classid}&keyword={$_GET['keyword']}";

    // -------------------------------------------------------
    // 保存编辑数据
    // -------------------------------------------------------
    if ($action=="submit") {
        $title = dhtmlspecialchars(check_empty($_POST["ad_title"],$clang[title]));
		$confirm = dhtmlspecialchars(check_numeric($_POST["confirm"],$clang[confirm]));
		$type = dhtmlspecialchars(check_numeric($_POST["type"],$clang[type]));
		$ad_url = dhtmlspecialchars($_POST["ad_url"]);
		$address = intval($_POST['address']);
        $upload = dhtmlspecialchars($_POST["images"]);
        $size = clear_br(dhtmlspecialchars($_POST["size"]));
		$put_ad = dhtmlspecialchars($_POST["put_ad"]);
        $addtime = date ("Y-m-d H:i:s", strtotime($_POST["addtime"]));
        $adduser = dhtmlspecialchars($_POST["adduser"]);
        $fields_arr = array(
            "title" => $title,
			"ad_url" => $ad_url,
			"address" => $address,
            "upload" => $upload,
            "confirm" => $confirm,
            "type" => $type,
			"size" => $size,
            "content" => $_POST["news_content"],
			"put_ad" => $put_ad,
            "addtime" => $addtime,
            "adduser" => $adduser
        );
		file_log($_SESSION['AdminUser'],"修改广告");
    }

    // -------------------------------------------------------
    // 执行页面处理
    // -------------------------------------------------------
	//$tpl->assign("classid", $classid);
    show_page_head($page_type, $page_title);
    $pedit = new PageEdit($page_title, $back_page, $page_type);
    $pedit->SetParam($table_name, $condition);
    $pedit->UpdateData($fields_arr);
    $pedit->TplParse($display_page);
    show_page_foot();
    $db->close();
?>